Test Series - java script

Test Number 24/92

Q: Which of the following is a way of embedding Client-side JavaScript code within HTML documents?
A. From javascript:encoding
B. External file specified by the src attribute of a “script” tag
C. By using a header tag
D. By using body tag
Solution: The Client-side JavaScript code is embedded within HTML documents in four ways :
Inline, between a pair of “script” tags
From an external file specified by the src attribute of a “script” tag
In an HTML event handler attribute, such as onclick or onmouseover
In a URL that uses the special javascript: protocol.
Q: When does JavaScript code appear inline within an HTML file?
A. Between the “script” tag
B. Outside the “script” tag
C. Between or Outside the “script” tag
D. Between the header tag
Solution: JavaScript code can appear inline within an HTML file between the “script” tags. Javascript can also be included from an external file specified by the src attribute of a “script” tag.
Q: Which character in JavaScript code will be interpreted as XML markup?
A. !
B. >
C. &
D. .
Solution: If your JavaScript code contains the < or & characters, these characters are interpreted as XML markup. Element tags must begin with the < character, and entities and character references in an XML document must begin with the & character.
Q: Which is the root element in a HTML document?
A. HTML
B. HEAD
C. SCRIPT
D. BODY
Solution: The “html” tag is the root element of any HTML document regardless of it containing a JavaScript code or not. Body tag includes the main content that is shown on the website.
Q: What is the code for getting the current time?
A. now = new Date();
B. var now = new Date();
C. var now = Date();
D. var now = new Date(current);
Solution: Date() is a predefined function in javascript which returns the date in string form. The above code determines the current time and stores it in the variable “now”.
Q: What is the code to start displaying the time when the document loads?
A. onload = displayTime;
B. window. = displayTime;
C. window.onload = displayTime;
D. window.onload = start;
Solution: window.onload is used to access the screen while the page is loading. The above code starts displaying the time when the document loads.
Q: One of the main advantage of using src attribute is ____________
A. It becomes self-cached
B. It makes the HTML file modular
C. It restricts manipulation in the HTML file
D. It simplifies the HTML files
Solution: The main advantage of using the src attribute is that it simplifies your HTML files by allowing you to remove large blocks of JavaScript code from them. Hence separate files for css and javascript files are made to make the code modular and readable.
Q: What will be done if more than one page requires a file of JavaScript code?
A. Downloads that many times
B. Retrives from the browser cache
C. Must be re executed
D. Must be included in all the pages
Solution: If a file of JavaScript code is shared by more than one page, it only needs to be downloaded once, by the first page that uses it—subsequent pages can retrieve it from the browser cache. This makes the loading process easier and hence faster.
Q: What is the default value of the type attribute?
A. text/css
B. text/javascript
C. html
D. xml
Solution: The default value of the type attribute is “text/javascript”. You can specify this type explicitly if you want, but it is never necessary.
Q: The language is commonly used to __________________
A. Specify the user’s language
B. Specify the language going to be scripted
C. No longer in use
D. Specify the programmer’s favourable language
Solution: The language attribute specifies the natural language of the content of a web page. The language attribute is deprecated and should no longer be used.

You Have Score    /10